package com.xcc.mota.screen;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;

import com.xcc.mota.sprite.BaseSprite;
import com.xcc.mota.sprite.TextSprite;
import com.xcc.mota.utils.AssetsLoad;
import com.xcc.mota.utils.Logger;

import static com.xcc.mota.screen.BaseScreen.ScreenEvent.MsgAbout;
import static com.xcc.mota.screen.BaseScreen.ScreenEvent.MsgLevel1;
import static com.xcc.mota.screen.BaseScreen.ScreenEvent.TypeExitGame;
import static com.xcc.mota.screen.BaseScreen.ScreenEvent.TypeOpenScreen;

/**
 * 菜单场景
 * Created by Administrator on 2018/1/8.
 */
public class MenuScreen extends BaseScreen implements BaseSprite.OnClickListener {
    public MenuScreen(Context context) {
        super(context);
        paint = new Paint();
        AssetsLoad assetsLoad = new AssetsLoad(context);
        bitmap = assetsLoad.getBitmap("logo.png");

        initSprite();
    }

    private void initSprite() {
        textStart = new TextSprite().setTextColor(0xFFffffff).setText("开始游戏").setTextSize(60);
        textStart.setX(ScreenWidth / 2);
        textStart.setY(700);
        textStart.setOnClickListener(this);
        addTouchSprite(textStart);

        textAbout = new TextSprite().setTextColor(0xFFffffff).setText("关于").setTextSize(60);
        textAbout.setX(ScreenWidth / 2);
        textAbout.setY(800);
        textAbout.setOnClickListener(this);
        addTouchSprite(textAbout);

        textExit = new TextSprite().setTextColor(0xFFffffff).setText("退出").setTextSize(60);
        textExit.setX(ScreenWidth / 2);
        textExit.setY(900);
        textExit.setOnClickListener(this);
        addTouchSprite(textExit);
    }

    private Bitmap bitmap;
    private TextSprite textStart, textAbout, textExit;
    private Paint paint;

    public void onDraw(Canvas canvas) {
        canvas.drawColor(0xff000000);
        if (Logger.isDebug) {
            paint.setColor(0xff0000FF);
            paint.setStyle(Paint.Style.STROKE);
            paint.setStrokeWidth(5);
            canvas.drawRect(0, 0, ScreenWidth, ScreenHeight - 5, paint);
        }

        if (bitmap != null) canvas.drawBitmap(bitmap, (ScreenWidth - 300) / 2, 300, paint);
        textStart.onDraw(canvas, paint);
        textAbout.onDraw(canvas, paint);
        textExit.onDraw(canvas, paint);
    }

    public void onClick(BaseSprite sprite) {
        if (textStart == sprite) {
            if (onScreenEvent != null) {
                onScreenEvent.onEvent(TypeOpenScreen, MsgLevel1);
            }
        } else if (textAbout == sprite) {
            if (onScreenEvent != null) {
                onScreenEvent.onEvent(TypeOpenScreen, MsgAbout);
            }
        } else if (textExit == sprite) {
            if (onScreenEvent != null) {
                onScreenEvent.onEvent(TypeExitGame, 0);
            }
        }
    }
}